package com.vn.toaa.karaoke.ui;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

import com.startapp.android.publish.Ad;
import com.startapp.android.publish.AdDisplayListener;
import com.startapp.android.publish.AdEventListener;
import com.startapp.android.publish.StartAppAd;
import com.startapp.android.publish.StartAppAd.AdMode;
import com.startapp.android.publish.splash.SplashConfig;


public class BaseAdsActivity extends Activity {

	public static final String TAG = BaseAdsActivity.class.getSimpleName();
	private StartAppAd mStartAppAds = new StartAppAd(this);

	private boolean mIsShowedExitAdWhenBack = false;

	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
	}

	@Override
	protected void onResume() {
		super.onResume();
		if (mStartAppAds != null) {
			mStartAppAds.onResume();
		}
	}

	@Override
	protected void onPause() {
		if (isFinishing()) {
			if (mStartAppAds != null && mIsShowedExitAdWhenBack) {
				mStartAppAds.onBackPressed();
			}
		}
		super.onPause();
		if (mStartAppAds != null) {
			mStartAppAds.onPause();
		}
	}
	
	@Override
	protected void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		if (mStartAppAds != null) {
			mStartAppAds.onSaveInstanceState(outState);
		}
	}
	
	@Override
	protected void onRestoreInstanceState(Bundle savedInstanceState) {
		if (mStartAppAds != null) {
			mStartAppAds.onRestoreInstanceState(savedInstanceState);
		}
		super.onRestoreInstanceState(savedInstanceState);
	}


	/**
	 * Show search box ads.
	 */
	public void showSliderAds() {
		StartAppAd.showSlider(this);
	}

	/**
	 * Show banner ads.
	 */
	public void showBannerAds() {
	}

	/**
	 * Show splash ad.
	 * 
	 * @param activity
	 *            the activity
	 * @param bundle
	 *            the bundle
	 */
	public void showSplashAd(Activity activity, Bundle bundle) {
		StartAppAd.showSplash(activity, bundle);
	}

	/**
	 * Show splash ad.
	 * 
	 * @param activity
	 *            the activity
	 * @param bundle
	 *            the bundle
	 * @param splashConfig
	 *            the splash config
	 */
	public void showSplashAd(Activity activity, Bundle bundle, SplashConfig splashConfig) {
		StartAppAd.showSplash(activity, bundle, splashConfig);
	}

	/**
	 * Show exit ad when back.
	 */
	public void showExitAdWhenBack() {
		mIsShowedExitAdWhenBack = true;
	}

	/**
	 * Show interstitial ad.
	 *
	 * @param adMode the ad mode
	 */
	public void showInterstitialAd(AdMode adMode) {
		if (mStartAppAds != null) {
			mStartAppAds.showAd(new AdDisplayListener() {
				
				@Override
				public void adHidden(Ad arg0) {
				}
				
				@Override
				public void adDisplayed(Ad arg0) {
				}
				
				@Override
				public void adClicked(Ad arg0) {
				}
			});
			mStartAppAds.loadAd(adMode, new AdEventListener() {

				@Override
				public void onReceiveAd(Ad arg0) {
				}

				@Override
				public void onFailedToReceiveAd(Ad arg0) {
				}
			});
		}
	}
	
}
